﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace homeIMSClient.Model
{
    //class represents assets for a user. mainly used for storing changes and updating to db through service
    public class asset
    {
        //private variables to store information
        private int _assetID;
        private int _userID;
        private int _typeID;
        private string _type;
        private string _name;
        private string _manufacturer;
        private int _qualityID;
        private string _quality;
        private string _IDNumber;
        private string _make;
        private string _model;
        private string _comments;
        private int _retailValue;
        private int _quantity;
        private DateTime _createDate;
        private DateTime _purchDate;
        private DateTime _lastUpdate;

        //private lists storing information for certain parts of asset
        private Model.purchInfo _purchInfo;
        private List<warrantyInfo> _warrantyInfo;
        private List<maintenanceInfo> _maintenanceInfo;


        //public variables for retrievable and changes
        public int AssetID
        {
            get { return _assetID; }
        }
        public int UserID
        {
            get { return _userID; }
        }
        public int TypeID
        {
            get { return _typeID; }
        }
        public int QualityID
        {
            get { return _qualityID; }
        }
        public string Type
        {
            get { return _type; }
            set { _type = value; }
        }
        public string Name
        {
            get { return _name; }
            set { _name = value; }
        }
        public string Manufacturer
        {
            get { return _manufacturer; }
            set { _manufacturer = value; }
        }
        public string Quality
        {
            get { return _quality; }
            
        }
        public string IDNumber
        {
            get { return _IDNumber; }
            set { _IDNumber = value; }
        }
        public string Make
        {
            get { return _make; }
            set { _make = value; }
        }
        public string Model
        {
            get { return _model; }
            set { _model = value; }
        }
        public string Comments
        {
            get { return _comments; }
            set { _comments = value; }
        }
        public int RetailValue
        {
            get { return _retailValue; }
            set { _retailValue = value; }
        }
        public int Quantity
        {
            get { return _quantity; }
            set { _quantity = value; }
        }
        public DateTime CreateDate
        {
            get { return _createDate; }
            
        }
        public DateTime PurchDate
        {
            get { return _purchDate; }
            set { _purchDate = value; }
        }
        public DateTime lastUpdate
        {
            get { return _lastUpdate; }
            set { _lastUpdate = value; }
        }
        public Model.purchInfo PurchaseInfo
        {
            get { return _purchInfo; }
            set { _purchInfo = value; }
        }
        public List<warrantyInfo> WarrantyInfo
        {
            get { return _warrantyInfo; }
            set { _warrantyInfo = value; }
        }
        public List<maintenanceInfo> maintInfo
        {
            get { return _maintenanceInfo; }
            set { _maintenanceInfo = value; }
        }

        //constructor runs method to hydrate class.
        public asset(homeIMSRef.assetInfo assetInfo)
        {
            //call method to hydrate and fill variables
            hydrateAsset(assetInfo);
        }

        private void hydrateAsset(homeIMSRef.assetInfo assetInfo)
        {
            //store information in private variables from information
            _assetID = assetInfo.assetID;
            _userID = assetInfo.userID;
            _typeID = assetInfo.typeID;
            _type = assetInfo.type;
            _name = assetInfo.name;
            _manufacturer = assetInfo.manufacturer;
            _qualityID = assetInfo.qualityID;
            _quality = assetInfo.quality;
            _IDNumber = assetInfo.IDNumber;
            _make = assetInfo.make;
            _model = assetInfo.model;
            _comments = assetInfo.comments;
            _retailValue = assetInfo.retailValue;
            _quantity = assetInfo.quantity;
            _createDate = assetInfo.createDate;
            _purchDate = assetInfo.purchDate;
            _lastUpdate = assetInfo.lastUpdate;

            //run through lists of details and store in lists
            purchInfo purchaseInfo = new purchInfo(assetInfo.purchInfo);

            _purchInfo = purchaseInfo;

            //run thorugh lists of maintentanceInfo and warrantyInfo and store in lists
            List<maintenanceInfo> maintList = new List<maintenanceInfo>();
            List<warrantyInfo> warrantyList = new List<warrantyInfo>();
                foreach (homeIMSRef.maintenanceInfo maintInfo in assetInfo.maintenanceList)
                {
                    //store information for each maintInfo and store in list
                    
                    maintenanceInfo newMaintInfo = new maintenanceInfo(maintInfo);

                    maintList.Add(newMaintInfo);
                }
                //store in list
                _maintenanceInfo = maintList;
            
                foreach (homeIMSRef.warrantyInfo warrantyInfo in assetInfo.warrantyList)
                {
                    //store information for each maintInfo and store in list
                    warrantyInfo newWarrantyInfo = new warrantyInfo(warrantyInfo);

                    //store in list
                    warrantyList.Add(newWarrantyInfo);
                }
                _warrantyInfo = warrantyList;
            
        }

    }
}
